const enterpriseVue = new Vue({
  el: "#app",
  data() {
    //校验身份证号
    var checkIDCard = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("身份证号不能为空"));
      }
      setTimeout(() => {
        if (!ID_Validity(value)) {
          callback(new Error("请输入正确的身份证号"));
        }
      }, 100);
    };
    //校验手机号
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      }
      setTimeout(() => {
        if (!validatemobile(value)) {
          callback(new Error("请输入正确的手机号"));
        } else {
          callback();
        }
      }, 100);
    };
    return {
      Service_Category: ["送货员", "部门主管", "技术人员", "测试人员"],
      pickerOptions: pickerOptions,
      rules: {
        Employee_Name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
        ],
        Mobile: [{ validator: checkIDCard, trigger: "blur" }],
        ID_Number: [{ validator: checkIDCard, trigger: "blur" }],
      },
      city: [],
      value1: [],
      form: {
        Employee_SerialNumber: "",
        Employee_Name: "",
        Mobile: "",
        ID_Number: "",
        Gender: "",
        Nation: "",
        Education: "",
        Residence_Address: "",
        Current_Residence_Address: "",
        Household_Register_Class: "",
        Entry_Date: "",
        Departure_Date: "",
        Contract_SerialNumber: "",
        Supplementary_Insurance: 0,
        DingTalk_UserID: "",
      },
      loading: false,
    };
  },
  mounted() {
    this.ciaaaaty();
    const Employee_SerialNumber = sessionStorage.getItem(
      "Employee_SerialNumber"
    );
    this.getData(Employee_SerialNumber);
  },
  methods: {
    ciaaaaty() {
      const that = this;
      $.ajax({
        url: absolutepath() + "utils/city.json",
        type: "GET",
        success: function (data) {
          that.city = data;
        },
        dataType: "json",
      });
    },
    handleID() {
      const that = this;
      if (this.form.Mobile) {
        $.ajax({
          url: `${BASE_URL1}/Getbymobile`,
          type: "POST",
          data: {
            mobile: this.form.Mobile,
          },
          success: function (res) {
            if (res.errmsg === "ok") {
              that.form.DingTalk_UserID = res.result.userid;
            } else {
              that.$message.error("获取失败");
            }
          },
          dataType: "json",
        });
      } else {
        this.$message({
          type: "warning",
          message: "请输入手机号",
        });
      }
    },
    getData(Employee_SerialNumber) {
      console.log(Employee_SerialNumber);
      const _this = this;
      $.ajax({
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        type: "post",
        data: {
          Data: "employee", //表名
          Condition:
            "Row_Status='0' And Employee_SerialNumber= '" +
            Employee_SerialNumber +
            "'",
        },
        success: function (res) {
          console.log(res);
          // Residence_Address: "河北省/秦皇岛市/山海关区"
          // let value1 = res[0].Residence_Address.split("/");
          // console.log(value1);
          _this.value1 = res[0].Residence_Address.split("/");
          console.log(_this.value1);
          console.log(_this.city);

          // this.value1[0] = value1[0];
          // this.value1[1] = value1[1];
          // this.value1[2] = value1[2];
          // this.value1[0] + "/" + this.value1[1] + "/" + this.value1[2];
          _this.form = res[0];
          // if (_this.form.Residence_Address) {
          //   _this.value1 = _this.form.Residence_Address.split("/");
          // }
        },
        // complete: function (XMLHttpRequest) {
        //   _this.loading = false
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // }
      });
      return;
    },
    submitForm(formName) {
      this.form.Residence_Address =
        this.value1[0] + "/" + this.value1[1] + "/" + this.value1[2];
      delete this.form.Operation_Datetime;
      delete this.form.Operation_Datetime_Original;
      console.log(this.form);
      let lArray = new Array();
      lArray.push(this.form);
      let lJSONObject_employee = new Object();
      lJSONObject_employee.employee = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_employee; //换表
      console.log(lJSONObject_DataSet);
      const _this = this;
      // return;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message.success("提交成功");
            window.history.go(-1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    deal() {
      const modify = deepClone(this.form);
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
});
